//
//  UIButton+Extension.swift
//  xlwb-swift
//
//  Created by 王世清 on 16/4/17.
//  Copyright © 2016年 wsq. All rights reserved.
//

import UIKit

extension UIButton {
    
    /// 便利构造函数
    ///
    /// - parameter imageName:     imageName
    /// - parameter backImageName: backImageName
    ///
    /// - returns: UIButton
    convenience init (imageName: String, backImageName: String) {
    //================
    self.init()
    
    setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
    setImage(UIImage(named: imageName), forState: UIControlState.Normal)
    setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
    setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
    
    //-------------设置button的大小 -根据背景图片的大小设置
    sizeToFit()
        
    }
    
    /// 便利构造函数
    ///
    /// - parameter title:     title
    /// - parameter color:     color
    /// - parameter backImage: backImage
    ///
    /// - returns: UIButton
    convenience init(title: String, color: UIColor, backImage: String) {
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImage), forState: UIControlState.Normal)
        
    }
    
}
